package com.htudata.live.controller;

import javax.servlet.http.HttpServletRequest;

import com.htudata.common.enums.RequestSeqEnum;
import com.htudata.common.enums.RequestStatusEnum;
import com.htudata.common.service.TokenService;
import com.htudata.common.vo.ResponseResult;
import com.htudata.core.util.ResultGenerator;
import com.htudata.live.service.LiveService;
import com.htudata.live.service.VirtualStationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LiveController {

  @Autowired
  private LiveService liveService;
  
  @Autowired
  private VirtualStationService virtualStationService;
  
  @Autowired
  private HttpServletRequest request;
  
  @RequestMapping(value = {"/v1/live/get3DFlows/{flowId}"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlowsList(@PathVariable("flowId") String flowId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService.get3DFlowList(flowId, 1, 0, a2, 37L));
    } catch (Exception e) {
      log.error("get3DFlowsList",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/dataTypes"}, method = {RequestMethod.GET})
  public ResponseResult getDataTypes(@RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_001.getCode(), this.liveService.getDataTypeList(), "获取数据类型成功");
    } catch (Exception e) {
      log.error("getDataTypes",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_001.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @Deprecated
  public ResponseResult getAlarms(@RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_003.getCode(), this.liveService.getAlarmList(), "获取当前告警列表数据成功");
    } catch (Exception e) {
      log.error("getAlarms",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_003.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/flowsAndNodes"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlows3(@RequestParam(required = false, defaultValue = "0") int alarm, @RequestParam(required = false, defaultValue = "0") int statis, @RequestParam(required = false, defaultValue = "-1") int nodeTypeId, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "0") int perPage, @RequestParam(required = false, defaultValue = "0") int stationTypeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_000.getCode(), this.liveService
          .get3DFlowList3(alarm, statis, nodeTypeId, page, perPage, stationTypeId, a2));
    } catch (Exception e) {
      log.error("get3DFlows3",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_000.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/nodes"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlows2(@RequestParam(required = true) int alarm, @RequestParam(required = true) int statis, @RequestParam(required = true) int nodeTypeId, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "0") int perPage, @RequestParam(required = false, defaultValue = "0") int stationTypeId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService
          .get3DFlowList2(alarm, statis, nodeTypeId, page, perPage, stationTypeId, a2));
    } catch (Exception e) {
      log.error("get3DFlows2",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v2/live/nodes"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlows2(@RequestParam(required = true) int alarm, @RequestParam(required = true) int statis, @RequestParam(required = true) int nodeTypeId, @RequestParam(required = false, defaultValue = "0") int page, @RequestParam(required = false, defaultValue = "0") int perPage, @RequestParam(required = false, defaultValue = "0") int stationTypeId, @RequestParam(required = false, defaultValue = "-2") int level, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService
          .get3DFlowListV2(alarm, statis, nodeTypeId, page, perPage, level, stationTypeId, a2));
    } catch (Exception e) {
      log.error("get3DFlows2",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/flows/{flowId}"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlows(@PathVariable String flowId, @RequestParam(required = true) int alarm, @RequestParam(required = true) int statis, @RequestParam(required = true) String a2) {
    try {
      long userId = TokenService.getUserId(this.request);
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService
          .get3DFlowList(flowId, alarm, statis, a2, userId), "获取3D流程图数据成功");
    } catch (Exception e) {
      log.error("get3DFlows",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/flowsMgt/{flowId}"}, method = {RequestMethod.GET})
  public ResponseResult get3DFlows(@PathVariable String flowId, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService
          .get3DFlowList(flowId, a2), "获取3D流程图数据成功");
    } catch (Exception e) {
      log.error("get3DFlows",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/virtualNodes"}, method = {RequestMethod.GET})
  public ResponseResult getVirtualNodes(@RequestParam(required = true) String nodeId, @RequestParam(required = false, defaultValue = "0") int V02001, @RequestParam(required = false, defaultValue = "") String V01301, @RequestParam(required = false, defaultValue = "") String stationName, @RequestParam(required = false, defaultValue = "") String V_PRCODE, @RequestParam(required = false, defaultValue = "") String V_CITY, @RequestParam(required = false, defaultValue = "") String V_ADDRESS, @RequestParam(required = true) int pageNum, @RequestParam(required = true) int pageSize, @RequestParam(required = true) String a2) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.liveService.getVirtualNodes(nodeId, V02001, V01301, stationName, V_PRCODE, V_CITY, V_ADDRESS, pageNum, pageSize), "获取虚拟站台子节点成功");
    } catch (Exception e) {
      log.error("getVirtualNodes",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/virtualStationList"}, method = {RequestMethod.GET})
  public ResponseResult getVirtualStationList(@RequestParam(required = true) String nodeId, @RequestParam(required = true) String provCode, @RequestParam(required = true) String areaCode, @RequestParam(required = true) int level, @RequestParam(required = true) int page, @RequestParam(required = true) int perPage) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.virtualStationService
          .getVirtualStationList(nodeId, provCode, areaCode, level, page, perPage), "获取虚拟台站节点列表成功");
    } catch (Exception e) {
      log.error("getVirtualStationList",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
  
  @RequestMapping(value = {"/v1/live/statisVirtualStation"}, method = {RequestMethod.GET})
  public ResponseResult getStatisVirtualStation(@RequestParam(required = true) String nodeId, @RequestParam("areaCode") String areaCode, @RequestParam(required = true) int level) {
    try {
      return ResultGenerator.genResult(RequestSeqEnum.SEQ_004.getCode(), this.virtualStationService.getStatisVirtualStation(nodeId, areaCode, level), "获取虚拟台站节点统计数据成功");
    } catch (Exception e) {
      log.error("getStatisVirtualStation",e);
      return ResultGenerator.genErrorResult(RequestSeqEnum.SEQ_004.getCode(), RequestStatusEnum.STATUS_503
          .getCode(), "暂无数据");
    } 
  }
}
